package com.platform.common.core.utils;

import com.github.pagehelper.PageInfo;
import com.platform.common.core.web.page.TableDataInfo;

import java.util.List;

/**
 * @Author: 可乐
 * @Description:
 * @CreateTime: 2023-11-09  11:39
 */
public class HandlerPageUtil {
	public static <T>TableDataInfo doPage(List<T> entityList, int pagenum, int pageSize) {
		int totalItems = entityList.size();
		int startIndex = (pagenum - 1) * pageSize;
		int endIndex = Math.min(startIndex + pageSize, totalItems);
		List< T > ts=null;
		if (startIndex > endIndex || startIndex >= totalItems) {

		} else {
			ts=entityList.subList( startIndex,endIndex );
		}
		TableDataInfo rspData = new TableDataInfo();
		rspData.setCode(200);
		rspData.setMsg("查询成功");
		rspData.setTotal((new PageInfo(entityList)).getTotal());
		rspData.setRows(ts);
		return rspData;
	}


}
